package com.xugui.thumb.controller;

import com.xugui.thumb.pojo.common.BaseResponse;
import com.xugui.thumb.pojo.common.ResultUtils;
import com.xugui.thumb.pojo.entity.Blog;
import com.xugui.thumb.pojo.vo.BlogVo;
import com.xugui.thumb.services.BlogService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("blog")
@RequiredArgsConstructor
public class BlogController {

    private final BlogService blogService;

    /**
     * 根据 ID 获取博客详情
     * @param blogId 博客 ID
     * @param request 请求
     * @return 博客详情
     */
    @GetMapping("/get")
    public BaseResponse<BlogVo> get(Long blogId, HttpServletRequest request) {
        BlogVo blogVO = blogService.getBlogVOById(blogId, request);
        return ResultUtils.success(blogVO);
    }

    /**
     * 获取博客列表
     * @param request 请求
     * @return 博客列表
     */
    @GetMapping("/list")
    public BaseResponse<List<BlogVo>> list(HttpServletRequest request) {
        List<Blog> blogList = blogService.list();
        List<BlogVo> blogVOList = blogService.getBlogVOList(blogList, request);
        return ResultUtils.success(blogVOList);
    }

}
